package com.jash.encryption;

import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    private DrawerLayout drawer;
    private MD5Fragment md5;
    private Base64Fragment base64;
    private DESFragment des;
    private RSAFragment rsa;
    private SignFragment sign;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        drawer = (DrawerLayout) findViewById(R.id.drawer);
        NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
        setSupportActionBar(toolbar);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, 0, 0);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
        navigationView.setNavigationItemSelectedListener(this);
        md5 = new MD5Fragment();
        base64 = new Base64Fragment();
        des = new DESFragment();
        rsa = new RSAFragment();
        sign = new SignFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.content, md5).commit();
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        switch (item.getItemId()) {
            case R.id.item_md5:
                transaction.replace(R.id.content, md5);
                break;
            case R.id.item_base64:
                transaction.replace(R.id.content, base64);
                break;
            case R.id.item_des:
                transaction.replace(R.id.content, des);
                break;
            case R.id.item_rsa:
                transaction.replace(R.id.content, rsa);
                break;
            case R.id.item_sign:
                transaction.replace(R.id.content, sign);
                break;
        }
        transaction.commit();
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}
